From f6dd1f6ceb12baa6aef8c8585e959eec75a4cd7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Mon, 13 Mar 2017 14:42:38 +0800 Subject: [PATCH] wayland: Throttle system bell requests If a bad behaving application tries to make the window/display beep too often, throttle the beep requests so that we don't end up filling the Wayland socket queue. The throttle is set to 50 beeps per second, which far more beeps than will ever make any sense from a user experience point of view, but will avoid terminating due to an excessive amount of requests. https://bugzilla.gnome.org/show_bug.cgi?id=778188 --- gdk/wayland/gdkdisplay-wayland.c | 9 +++++++++ gdk/wayland/gdkdisplay-wayland.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index 0cca86ca7c..0baa2de21c 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -83,6 +83,8 @@ * ]| */ +#define MIN_SYSTEM_BELL_DELAY_MS 20 + static void _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland); G_DEFINE_TYPE (GdkWaylandDisplay, gdk_wayland_display, GDK_TYPE_DISPLAY) @@ -666,6 +668,7 @@ gdk_wayland_display_system_bell (GdkDisplay *display, { GdkWaylandDisplay *display_wayland; struct gtk_surface1 *gtk_surface; + gint64 now_ms; g_return_if_fail (GDK_IS_DISPLAY (display)); @@ -679,6 +682,12 @@ gdk_wayland_display_system_bell (GdkDisplay *display, else gtk_surface = NULL; + now_ms = g_get_monotonic_time () / 1000; + if (now_ms - display_wayland->last_bell_time_ms < MIN_SYSTEM_BELL_DELAY_MS) + return; + + display_wayland->last_bell_time_ms = now_ms; + gtk_shell1_system_bell (display_wayland->gtk_shell, gtk_surface); } diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h index a68940f5b8..1270405e11 100644 --- a/gdk/wayland/gdkdisplay-wayland.h +++ b/gdk/wayland/gdkdisplay-wayland.h @@ -110,6 +110,8 @@ struct _GdkWaylandDisplay GPtrArray *monitors; + gint64 last_bell_time_ms; + /* egl info */ EGLDisplay egl_display; int egl_major_version; -- 2.30.2